import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    users: {

      userName: window.localStorage.getItem('users' || '[]') == null ? '未登录' : JSON.parse(window.localStorage.getItem('users' || '[]')).userName,
      userImg: window.localStorage.getItem('users' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('users' || '[]')).userImg
    },
    routes: []
  },
  mutations: {
    initMenu(state, Resources){
      state.routes = Resources;
    },
    login(state, users){
      state.users = users;
      window.localStorage.setItem('users', JSON.stringify(users));
    },
    logout(state){
      window.localStorage.removeItem('users');
      state.routes = [];
    }
  },
  actions: {
  }
});
